package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.*;
import com.indusfo.spc.pojo.BatchFlow;
import com.indusfo.spc.pojo.BatchFlow;
import com.indusfo.spc.pojo.BatchFlow;
import com.indusfo.spc.service.BatchFlowService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liub
 * @Date 2019/12/4 15:57
 * @Version 1.0
 */

@Controller
@RequestMapping("/service/batchFlow")
public class BatchFlowController {

    @Autowired
    private BatchFlowService batchFlowService;

    /**
     * 查询
     */
    @RequestMapping(value = "/queryBatchFlow")
    @ResponseBody
    public JSONObject queryBatchFlow(BatchFlow batchFlow) {
        JSONObject json = batchFlowService.queryBatchFlow(batchFlow);
        return json;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/insertBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertBatchFlow(BatchFlow batchFlow) {
        JSONObject json = batchFlowService.insertBatchFlow(batchFlow);
        return json;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateBatchFlow(BatchFlow batchFlow) {
        JSONObject json = batchFlowService.updateBatchFlow(batchFlow);
        return json;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/deleteBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteBatchFlow(@RequestParam("batchFlowIds") List<Integer> batchFlowIds, Integer dataState) {
        dataState = 2;
        JSONObject json = batchFlowService.deleteBatchFlow(batchFlowIds, dataState);
        return json;
    }

    /**
     * 级联删除工序流程关联的工位、采集参数、关键物料、不良现象
     */
    @RequestMapping(value = "/deleteCascadeBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeBatchFlow(@RequestParam("batchFlowIds") List<Integer> batchFlowIds, Integer dataState) {
        dataState = 2;
        try {
            return batchFlowService.deleteCascadeBatchFlow(batchFlowIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }

    /**
     * 启停
     */
    @RequestMapping(value = "/definedBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedBatchFlow(@RequestParam("batchFlowIds") List<Integer> batchFlowIds, Integer dataState) {
        JSONObject json = batchFlowService.deleteBatchFlow(batchFlowIds, dataState);
        return json;
    }

    /**
     * 保存流程工位
     */
    @RequestMapping(value = "/saveBatchStation", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchStation(@RequestBody BatchFlow batchFlow) {
        JSONObject json = batchFlowService.saveBatchStation(batchFlow);
        return json;
    }

    /**
     * 保存流程采集参数
     */
    @RequestMapping(value = "/saveBatchDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchDete(@RequestBody BatchFlow batchFlow) {
        JSONObject json = batchFlowService.saveBatchDete(batchFlow);
        return json;
    }

    /**
     * 保存流程物料
     */
    @RequestMapping(value = "/saveBatchBom", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchBom(@RequestBody BatchFlow batchFlow) {
        JSONObject json = batchFlowService.saveBatchBom(batchFlow);
        return json;
    }

    /**
     * 保存不良现象
     */
    @RequestMapping(value = "/saveBatchBadpheno", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveBatchBadpheno(@RequestBody BatchFlow batchFlow) {
        JSONObject json = batchFlowService.saveBatchBadpheno(batchFlow);
        return json;
    }

    /**
     * @Author 熊冰  任务单流程导入批次流程
     * @Date 2019/12/4 14:47
     */
    @RequestMapping(value = "/leadBatchFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject leadBatchFlow(Integer orderId, Integer batchId, String batchCode) {
        JSONObject json = batchFlowService.leadBatchFlow(orderId, batchId, batchCode);
        return json;
    }

    /**
     * 批次流程维修下工序新增查询
     */
    @RequestMapping(value = "/queryListBatchFlowToInsert")
    @ResponseBody
    public JSONObject queryListBatchFlowToInsert(BatchFlow batchFlow) {
        JSONObject json = batchFlowService.queryListBatchFlowToInsert(batchFlow);
        return json;
    }
}
